package global

import (
	"github.com/sirupsen/logrus"
	"miao-server/structs/tables"
)

func autoMigrate() {
	type vector[T any] []T
	var li = vector[interface{}]{
		&tables.Device{},
		&tables.DeviceAbnormal{},
		&tables.LogCollect{},
		&tables.LogLoad{},
		&tables.Policy{},
	}
	for _, item := range li {
		if !DB.Migrator().HasTable(item) {
			err := DB.AutoMigrate(item)
			if err != nil {
				logrus.Errorf("初始化数据库表结构异常: %v", err)
			}
		}
	}
}
